package com.qingfeng.client.bean;

import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;

/**
 * 订单处理延迟消息
 *
 * @author zhangyuefei
 * @version 1.0
 * @date 2020/1/9 2:52 下午
 */
public class TradeQueueMsg implements Delayed {

    /**
     * 1表示待收货订单，
     * 2表示待关闭订单
     */
    private Integer type;

    private Long orderStoreId;

    private Long expiredTime;


    @Override
    public long getDelay(TimeUnit unit) {
        return unit.convert(expiredTime , TimeUnit.NANOSECONDS)
                - unit.convert(System.currentTimeMillis(), TimeUnit.NANOSECONDS);
    }

    @Override
    public int compareTo(Delayed o) {
        if (this == o) {
            return 1;
        }
        if (o == null) {
            return -1;
        }
        long diff = this.getDelay(TimeUnit.NANOSECONDS) - o.getDelay(TimeUnit.NANOSECONDS);
        return diff < 0 ? -1 : (diff == 0 ? 0 : 1);
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public Long getOrderStoreId() {
        return orderStoreId;
    }

    public void setOrderStoreId(Long orderStoreId) {
        this.orderStoreId = orderStoreId;
    }

    public Long getExpiredTime() {
        return expiredTime;
    }

    public void setExpiredTime(Long expiredTime) {
        this.expiredTime = expiredTime;
    }
}
